package com.chen.hotel.Service.impl;

import com.chen.hotel.Service.RoomService;
import com.chen.hotel.dao.RoomDao;
import com.chen.hotel.domain.Room;
import com.chen.hotel.utils.CopyNotNullUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomDao roomDao;

    @Override
    public Room create(Room room) {
        return this.roomDao.save(room);
    }

    @Override
    public Room update(Room room) {
        Room r = this.getRoomById(room.getId());
        CopyNotNullUtil.copyNoNullProperties(room, r);
        return this.roomDao.save(r);
    }

    @Override
    public void deleteById(Integer id) {
        this.roomDao.deleteById(id);
    }

    @Override
    public Room getRoomById(Integer id) {
        return this.roomDao.findById(id).get();
    }

    @Override
    public Page<Room> getAllRoom(Pageable request) {
        return this.roomDao.findAll(request);
    }

    @Override
    public Page<Room> getRoomByType(Pageable request, Integer typeId) {
        return this.roomDao.findByType(typeId, request);
    }

    @Override
    public Page<Room> getRoomByFloor(Pageable request, Integer floor) {
        return this.roomDao.findByFloor(floor, request);
    }

    @Override
    public Page<Room> getRoomByStatus(Pageable request, Integer status) {
        return this.roomDao.findByStatus(status, request);
    }
}
